package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.service.IWalletService;
import com.ruoyi.util.paypassword.PasswordVerifiers;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.PayInfoMapper;
import com.ruoyi.system.domain.PayInfo;
import com.ruoyi.system.service.IPayInfoService;

import javax.annotation.Resource;

/**
 * 支付密码Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-06
 */
@Service
public class PayInfoServiceImpl implements IPayInfoService 
{
    @Resource
    private PayInfoMapper payInfoMapper;
    @Resource
    private IWalletService walletService;
    /**
     * 查询支付密码
     * 
     * @param userId 支付密码主键
     * @return 支付密码
     */
    @Override
    public PayInfo selectPayInfoByUserId(Long userId)
    {
        return payInfoMapper.selectPayInfoByUserId(userId);
    }

    /**
     * 查询支付密码列表
     * 
     * @param payInfo 支付密码
     * @return 支付密码
     */
    @Override
    public List<PayInfo> selectPayInfoList(PayInfo payInfo)
    {
        return payInfoMapper.selectPayInfoList(payInfo);
    }

    /**
     * 新增支付密码
     * 
     * @param payInfo 支付密码
     * @return 结果
     */
    @Override
    @PasswordVerifiers
    public int insertPayInfo(PayInfo payInfo){
        PayInfo info = payInfoMapper.selectPayInfoByUserId(payInfo.getUserId());
        if(info != null){
            return 0;
        }
        walletService.insertWallet(payInfo.getUserId());
        return payInfoMapper.insertPayInfo(payInfo);
    }

    /**
     * 修改支付密码
     * 
     * @param payInfo 支付密码
     * @return 结果
     */
    @Override
    @PasswordVerifiers
    public int updatePayInfo(PayInfo payInfo){
        return payInfoMapper.updatePayInfo(payInfo);
    }

    /**
     * 批量删除支付密码
     * 
     * @param userIds 需要删除的支付密码主键
     * @return 结果
     */
    @Override
    public int deletePayInfoByUserIds(Long[] userIds)
    {
        return payInfoMapper.deletePayInfoByUserIds(userIds);
    }

    /**
     * 删除支付密码信息
     * 
     * @param userId 支付密码主键
     * @return 结果
     */
    @Override
    public int deletePayInfoByUserId(Long userId)
    {
        return payInfoMapper.deletePayInfoByUserId(userId);
    }
}
